<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/add.css"/>
	</head>
	<body>
		<div id="app">
			<div class="header">
				<span>修改快递信息</span>
			</div>
			<div class="content">
				<table>	
					<tr>
						<td class="text-right">运单号</td><td class="content_right"><input class="input inline-input" id="number" placeholder="请输入运单号码"> <span id="find" class="btn btn-info">立即查找</span></td>
					</tr>
				</table>
			</div>
			
			
			<div class="header">
				<span>查找信息如下</span>
			</div>
			<div class="content">
				<table>
					<tr>
						<td class="text-right">快递单号</td><td class="content_right"><input class="input" placeholder="请输入单号" id="editNumber"></td>
					</tr>
					<tr>
						<td class="text-right">快递公司</td><td class="content_right"><input class="input" placeholder="请输入快递公司" id="editCompany"></td>
					</tr>
					<tr>
						<td class="text-right">收货人姓名</td><td class="content_right"><input class="input" placeholder="请输入收件人姓名" id="editUsername"></td>
					</tr>
					<tr>
						<td class="text-right">手机号码</td><td class="content_right"><input class="input" placeholder="请输入收件人手机号码" id="editUserPhone" onblur="isPhoneNum()"></td>
					</tr>
					<tr>
						<td class="text-right">快递状态</td><td class="content_right"><input type="radio" class="status" name="status" value="1" >已签收  <input name="status" type="radio" class="status" value="0" >未签收</td>
					</tr>
					<tr>
						<td></td><td class="content_right"><span class="btn btn-info" id="update">立即修改</span> <span class="btn">重置</span> </td>
					</tr>
				</table>
			</div>
		</div>
	</body>

	<script src="/qrcode/jquery2.1.4.js"></script>
	<script src="/layer/layer.js"></script>
	<script>
		$(".header:eq(1),.content:eq(1)").hide();
		var expressId = null;
		var editNumber = null;
		var editCompany = null;
		var editUsername = null;
		var editUserPhone = null;
		var status = null;
		var checkNumber = null;
		var g_UserPhone = null;

		$(function () {
			$("#find").click(function () {
				var windowId = layer.load();
				var number = $("#number").val();
				$.getJSON("/express/find.do",{number:number},function (data) {
					layer.close(windowId);
					layer.alert(data.result);
					// 查找到对应单号的快递
					if (data.status == 0){
						// 1秒渐渐显示快递具体信息
						$(".header:eq(1),.content:eq(1)").fadeIn(1000);
						// {"result":"查询成功",
						// "data":{"id":1,"number":"SF1111","username":"张三","userPhone":"15312341234","company":"顺丰速递","inTime":"Jul 29, 2021, 11:42:56 AM","outTime":"Jul 29, 2021, 11:42:56 AM","sysPhone":"18856334567","status":1},
						// "status":0}
						expressId = data.data.id;
						g_UserPhone = data.data.userPhone;
						$("input:eq(1)").val(data.data.number);
						$("input:eq(2)").val(data.data.company);
						$("input:eq(3)").val(data.data.username);
						$("input:eq(4)").val(data.data.userPhone);
						if (data.data.status==1){
							// 已签收快递
							$(".status:eq(0)").prop("checked",true);
						}else {
							// 未签收快递
							$(".status:eq(1)").prop("checked", true);
						}

						// TODO:当用户在单号的输入框上失去焦点的时候，就去查询与已有的单号是否重复
						$("#editNumber").blur(function () {

							checkNumber = $("input:eq(1)").val();

							if (checkNumber != ""){
								$.getJSON("/express/insertCheckByNumber.do",{checkNumber:checkNumber},function (data) {
									if (data.status==-1){
										layer.alert("单号重复");
									}
								});
							}else {
								layer.alert("快递单号不能为空！");
								$("input:eq(1)").val(checkNumber);
							}
						});

						// 前面的查询结束，下面进行修改主体部分的操作
						$("#update").click(function () {
							var windowId = layer.load();
							editNumber = $("#editNumber").val();
							editCompany = $("#editCompany").val();
							editUsername = $("#editUsername").val();
							editUserPhone = $("#editUserPhone").val();
							// 单选框的获取值的方法
							status = $(".status:checked").val();

							var express = {
								expressId:expressId,
								editNumber:editNumber,
								editCompany:editCompany,
								editUsername:editUsername,
								status:status
							};

							if (g_UserPhone != editUserPhone){
								express.editUserPhone = editUserPhone;
							}else {
								express.editUserPhone = g_UserPhone;
							}

							$.getJSON("/express/update.do",express,function (data) {
								// 关闭圈圈
								layer.close(windowId);
								layer.alert(data.result);

								if (data.status==0){
									// 修改成功
									// 修改成功就将快递具体信息隐藏起来
									$(".header:eq(1),.content:eq(1)").hide();
								};
							});

						});
					};
				});

			});
		});
	</script>
	<script>

		/*校验手机号*/
		function isPhoneNum() {
			// 如果因为现有的号码不能满足市场需求，电信服务商会增大号码范围。
			// 所以一般情况下只要验证手机号码为11位，且以1开头。
			var str = document.getElementById("editUserPhone").value;
			var reg = /^^1[0-9]{10}$$/;
			if (!reg.test(str)){
				layer.alert("请正确输入手机号！");
			}
			return reg.test(str);
		}

	</script>

</html>
